<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class AdminMenu extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change(): void
    {
        $table = $this->table('admin_menu', [
            'collation' => 'utf8mb4_general_ci'
        ]);
        $table->addColumn('menu_name', 'string', [
            'limit' => 32, 'null' => false, 'default' => '', 'comment' => '前端菜单名称'
        ]);
        $table->addColumn('menu_symbol', 'string', [
            'limit' => 64, 'null' => false, 'default' => '', 'comment' => '前端路标识, 建议使用组件name, 不能重复'
        ]);
        $table->addColumn('menu_icon', 'string', [
            'limit' => 64, 'null' => false, 'default' => '', 'comment' => '前端菜单图标'
        ]);
        $table->addColumn('menu_type', 'integer', [
            'limit' => 1, 'null' => false, 'default' => '1', 'comment' => '前端菜单类型：1菜单 2功能'
        ]);
        $table->addColumn('menu_affix', 'integer', [
            'limit' => 1, 'null' => false, 'default' => '0', 'comment' => '前端菜单是否固定到标签栏 0否 1是'
        ]);
        $table->addColumn('menu_visible', 'integer', [
            'limit' => 1, 'null' => false, 'default' => '1', 'comment' => '前端菜单是否在左侧显示 0否 1是'
        ]);
        $table->addColumn('menu_cache', 'integer', [
            'limit' => 1, 'null' => false, 'default' => '0', 'comment' => '前端页面是否keepalive 0否 1是'
        ]);
        $table->addColumn('api_name', 'string', [
            'limit' => 128, 'null' => false, 'default' => '', 'comment' => '接口名称, 用来匹配接口是否有请求权限'
        ]);
        $table->addColumn('api_path', 'string', [
            'limit' => 128, 'null' => false, 'default' => '', 'comment' => '接口路由地址'
        ]);
        $table->addColumn('api_method', 'string', [
            'limit' => 8, 'null' => false, 'default' => '', 'comment' => '接口请求方式GET/POST/PUT/DELETE'
        ]);
        $table->addColumn('list_order', 'integer', [
            'limit' => 1, 'null' => false, 'default' => '0', 'comment' => '排序 倒序'
        ]);
        $table->addColumn('parent_id', 'integer', [
            'limit' => 1, 'null' => false, 'default' => '0', 'signed' => false, 'comment' => '父级id'
        ]);
        $table->addColumn('create_time', 'datetime', [
            'comment' => '创建时间'
        ]);
        $table->addColumn('update_time', 'datetime', [
            'comment' => '更新时间'
        ]);
        $table->addColumn('delete_time', 'datetime', [
            'comment' => '删除时间'
        ]);
        $table->addIndex(['api_name'], ['name' => 'idx_api_name']);
        $table->addIndex(['api_path'], ['name' => 'idx_api_path']);
        $table->create();
    }
}
